<?php

namespace app\model\user;

use basic\BaseModel;
use think\db\BaseQuery;

class User extends BaseModel
{

    protected $name = "user";

    /**
     * Description: 是否软删除
     * @var bool
     */
    public $isSoftDelete = true;

    /**
     * Description: 软删除字段
     * @var string
     */
    public $softDeleteField = 'delete_time';

    public function searchPidAttr($query, $value)
    {
        if (is_array($value)) {
            $query->whereIn('pid', $value);
        } else {
            $query->where('pid', $value);
        }
    }

    public function searchNicknameAttr($query, $value)
    {
        $query->where('nickname', $value);
    }

    public function searchCreatTimeAttr($query, $value)
    {
        $query->where('create_time', $value);
    }

    /**
     * Description: 设置手机号搜索器
     *
     * @param BaseQuery    $query
     * @param string|array $value
     * @param              $data
     */
    public function searchPhoneAttr($query, $value)
    {
        $query->where('phone', $value);
    }

    /**
     * Description: 设置会员等级搜索器
     *
     * @param BaseQuery    $query
     * @param string|array $value
     * @param              $data
     */
    public function searchMemberIdAttr($query, $value)
    {
        $query->where('member_id', $value);
    }

    /**
     * Description: 设置是否冻结会员搜索器
     *
     * @param BaseQuery    $query
     * @param string|array $value
     * @param              $data
     */
    public function searchIsDisableAttr($query, $value)
    {
        $query->where('is_disable', $value);
    }

    /**
     * Description: 设置删除时间搜索器
     *
     * @param BaseQuery    $query
     * @param string|array $value
     * @param              $data
     */
    public function searchDeleteTimeAttr($query, $value)
    {
        $query->where('delete_time', $value ? '<>' : '=', 0);
    }

}